package com.monitor.core.handler;

import com.alibaba.fastjson.JSON;
import com.monitor.core.bean.MonitorMessage;
import com.monitor.core.config.RabbitConfig;
import com.monitor.core.util.MessageUtil;
import org.apache.log4j.Logger;
import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * @Auther: hanhui.liu
 * @Date: 2018/4/24 14:18
 * @Description:
 */
@Component
public class RabbitMQMessageHandler extends MessageHandler {

    private static final Logger logger = Logger.getLogger(RabbitMQMessageHandler.class);

    @Resource
    private AmqpTemplate amqpTemplate;

    @Override
    public void send(MonitorMessage monitorMessage) {
        logger.info("RabbitMQMessage handler send start");
        logger.info(JSON.toJSONString(monitorMessage));
        amqpTemplate.convertAndSend(RabbitConfig.QUEUEKEY, JSON.toJSONString(monitorMessage));
        logger.info("RabbitMQMessage handler send end");
    }
}
